<template>
	<view class="being">
		<view class="content">

			<view class="top" :style="{'padding-top': paddingTop}">
				<uni-icons @click="toBackPage" style="margin-left: 30rpx;width: 50rpx;" type="left" size="25"
					color="#2c2c2c">
				</uni-icons>
				<view style="display: flex;flex-direction: row;text-align:center;width: 150rpx;margin-left: 220rpx;">
					全部创作</view>
			</view>

			<view class="search">
				<uni-icons type="search" size="25" color="#2c2c2c"></uni-icons>
				<input @blur="pageCourse" style="width:570rpx" placeholder="请输入知桨名称或描述关键词" v-model="queryInput.name" />
			</view>

			<view class="course-list" v-if="courseList != null && courseList.length > 0">
				<view v-for="(course,index) in courseList" @click="goCourseStudy(course.id)" class="course">

					<view class="course-top">
						<view class="cover">
							<img class="image" :src="course.cover"></img>
						</view>
						<view class="info">
							<view class="name">{{course.name}}</view>
							<view class="description">
								<view style="margin-bottom: 20rpx;">学习进度{{course.progress}}%</view>
								<view class="out">
									<view class="inner" :style="{'width': course.progress + '%'}"></view>
								</view>
							</view>
						</view>
					</view>

					<view class="locate" @click.stop="goSectionStudy(course.lastSectionId)">
						上次学到：{{course.lastSectionName}}
					</view>
				</view>
			</view>

			<view class="course-empty" v-else>
				<view class="text">暂时没有更多</view>
			</view>


		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				queryInput: {
					pageNow: 1,
					pageSize: 20,
					total: 0,
					name: ""
				},
				courseList: [],
				paddingTop: null
			}
		},
		onLoad() {
			// 调整搜索位置
			// #ifdef MP-WEIXIN
			// 1.获取屏幕可使用宽度
			let windowWidth = uni.getSystemInfoSync().windowWidth;
			// 3.获取胶囊按钮位置信息
			const menuButton = uni.getMenuButtonBoundingClientRect();
			// // 5.导航栏与状态栏拉开距离  margin-top: statusBarTop + 'rpx';
			this.paddingTop = menuButton.top * (750 / windowWidth) + 'rpx';
			// #endif
		},
		onShow() {
			this.pageCourseProgress()
		},
		onReachBottom() {
			this.queryInput.pageNow++
			this.$api.pageCourseProgress(this.queryInput).then(res => {
				this.courseList = [...this.courseList, ...res.data.rows]
			})
		},
		methods: {
			pageCourseProgress() {
				this.$api.pageCourseProgress(this.queryInput).then(res => {
					this.courseList = res.data.rows
					this.queryInput.total = res.data.totalPage
				})
			},

			goSectionStudy(sectionId) {
				uni.navigateTo({
					url: '/pages_being/course/section-study?sectionId=' + sectionId
				})
			},
			goCourseStudy(courseId) {
				uni.navigateTo({
					url: '/pages_being/course/course-study?courseId=' + courseId
				})
			},
			toBackPage(){
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped lang="scss">
	.being {
		background-color: #FAFAFA;
		min-height: 100vh;

		.content {
			display: flex;
			flex-direction: column;

			.top {
				width: 100%;
				height: 50rpx;
				//#ifdef MP-WEIXIN
				width: 550rpx;
				//#endif

				padding-top: 100rpx;

				// #ifdef H5
				padding-top: 40rpx;
				// #endif

				padding-bottom: 20rpx;

				display: flex;
				flex-direction: row;
				align-items: center;
				box-shadow: 1px 1px 8px 2px #f0f0f0;
			}


			.search {
				height: 80rpx;
				width: 640rpx;
				margin: 30rpx 0 30rpx 30rpx;
				background-color: #FFFFFF;
				box-shadow: 1px 1px 8px 2px #f0f0f0;
				border-radius: 20rpx;

				padding: 0 20rpx;

				display: flex;
				flex-direction: row;
				justify-content: space-between;
				align-items: center;


			}

			.title {
				font-size: 36rpx;
				font-weight: bold;
				margin: 30rpx 0 30rpx 30rpx;
				position: relative;
				width: 690rpx;
				display: flex;
				flex-direction: row;
				justify-content: space-between;

				.mark {
					width: 45rpx;
					height: 35rpx;
					background-color: #B3DFDE;
					border-radius: 40%;
					position: absolute;

					top: 5rpx;
					left: 0;
					z-index: 1;
				}

				.text {
					padding-left: 15rpx;
					position: relative;
					z-index: 2;
					letter-spacing: 4rpx;
				}

				.right {
					display: flex;
					flex-direction: row;
					align-items: center;
					font-size: 28rpx;
					margin-bottom: 5rpx;
					font-weight: normal;
				}

			}

			.island-list {
				display: flex;
				flex-direction: row;
				align-items: center;
				width: 720rpx;
				margin-left: 30rpx;
				height: 180rpx;
				overflow: scroll;

				.island {
					width: 300rpx;
					height: 180rpx;
					margin-right: 30rpx;
					border-radius: 20rpx;
					color: white;

					display: flex;
					flex-direction: column;
					align-items: flex-start;
					justify-content: flex-end;
					box-shadow: 1px 1px 8px 2px #e9eee9;
				}

			}

			.course-empty {
				width: 690rpx;
				margin-left: 30rpx;
				height: 50rpx;
				border-radius: 20rpx;

				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;

				.text {
					letter-spacing: 5rpx;
					color: #818181;
				}


			}


			.course-list {
				display: flex;
				flex-direction: column;
				width: 690rpx;
				margin-left: 30rpx;


				.course {
					display: flex;
					flex-direction: column;

					margin-bottom: 30rpx;

					.course-top {
						display: flex;
						flex-direction: row;
						justify-content: space-between;

						.cover {
							width: 300rpx;
							height: 190rpx;
							border-radius: 20rpx;
							overflow: hidden;
						}

						.info {
							display: flex;
							flex-direction: column;
							justify-content: space-between;


							width: 350rpx;
							height: 190rpx;

							.name {
								margin-top: 5rpx;
								font-size: 36rpx;
							}

							.description {
								margin-top: 5rpx;
								color: gray;
								width: 100%;
								display: flex;
								flex-direction: column;
								justify-content: space-between;

								.out {
									width: 240rpx;
									margin-right: 20rpx;
									height: 12rpx;
									border-radius: 10rpx;
									background-color: #ececec;
									margin-bottom: 10rpx;

									.inner {
										height: 12rpx;
										border-radius: 10rpx;
										background-color: #5DACB1;
									}

								}

							}


						}

					}




					.locate {
						width: 650rpx;
						height: 60rpx;
						background-color: #ececec;
						border-radius: 10rpx;
						margin-top: 20rpx;
						line-height: 60rpx;
						padding-left: 20rpx;
						color: #555555;
					}

				}
			}

		}

	}


	image {
		width: 100%;
		height: 100%;
	}

	img {
		width: 100%;
		height: 100%;
		object-fit: cover;
	}
</style>
